package offer;


import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;



 public class BoardListAction extends ActionSupport implements ServletRequestAware{
		BoardDAO boarddao=new BoardDAO();
		List boardlist=new ArrayList();
		HttpServletRequest request;
		
		public String execute() throws Exception{
		System.out.println("1");
	  	int page=1;
		int limit=10;
		
		if(request.getParameter("page")!=null){
			page=Integer.parseInt(request.getParameter("page"));
		}
		
		int listcount=boarddao.getListCount(); 
		boardlist = boarddao.getBoardList(page,limit);
		
		
   		int maxpage=(int)((double)listcount/limit+0.95); 
   		System.out.println("maxpage======"+maxpage);
   		
   		int startpage = (((int) ((double)page / 10 + 0.9)) - 1) * 10 + 1;
   		
   		int endpage = maxpage;
   		
   		if (endpage>startpage+10-1) endpage=startpage+10-1;
   		
   		request.setAttribute("page", page);		 
   		request.setAttribute("maxpage", maxpage); 
   		request.setAttribute("startpage", startpage); 
   		request.setAttribute("endpage", endpage);    
		request.setAttribute("listcount",listcount); 
		request.setAttribute("boardlist", boardlist);
		
		
   		return SUCCESS;
	 }

		@Override
		public void setServletRequest(HttpServletRequest request) {
			this.request = request;
			
		}
 }